import request from './request'
import type { Permission, PaginationParams, PaginationResponse } from '@/types'

export const permissionAPI = {
  getPermissions: (params: PaginationParams & { 
    name?: string; 
    code?: string; 
    type?: number 
  }): Promise<PaginationResponse<Permission>> => {
    return request.get('/permissions', { params })
  },
  
  getPermission: (id: number): Promise<Permission> => {
    return request.get(`/permissions/${id}`)
  },
  
  createPermission: (data: {
    name: string
    code: string
    description?: string
    type: number
    parent_id?: number
    path?: string
    method?: string
  }): Promise<Permission> => {
    return request.post('/permissions', data)
  },
  
  updatePermission: (id: number, data: {
    name: string
    description?: string
    type: number
    parent_id?: number
    path?: string
    method?: string
  }): Promise<Permission> => {
    return request.put(`/permissions/${id}`, data)
  },
  
  deletePermission: (id: number): Promise<void> => {
    return request.delete(`/permissions/${id}`)
  },
  
  getPermissionTree: (): Promise<Permission[]> => {
    return request.get('/permissions/tree')
  }
}